<template>
  <div class="course" @click="handleCourse(course)">
    <el-row type="flex" align="middle" class="course-base">
      <div>
        <div class="course-name">{{ course.name }}</div>
        <div class="course-techer">
          <!--<template v-for="teacher in course.teacherList">-->
          <!--  <span :key="teacher.id" class="teacher">{{ teacher.realName }}</span>-->
          <!--</template>-->
          <span class="teacher">{{ course.teacherList[0].realName }}</span>
          <span class="age">{{ course.age }}</span>
        </div>
        <div class="course-time">
          {{ parseTime(course.startTime, '{y}.{m}.{d}') + ' - ' + parseTime(course.finishTime, '{m}.{d}') }}
        </div>
      </div>
      <el-image :src="course.url" class="course-image" />
    </el-row>
    <el-row type="flex" align="middle" justify="space-between" class="course-sale">
      <div class="people-info">
        <div class="limit">限售{{ course.capacity }}</div>
        <div>已售{{ course.capacity - course.surplus }}</div>
      </div>
      <div class="price-info">
        <span>￥</span>
        {{ course.price }}
      </div>
    </el-row>
  </div>
</template>

<script>
import { parseTime } from '@/utils'

export default {
  name: 'CourseItem',
  props: {
    course: {
      required: true,
      type: Object,
      default: function() {
        return {
          id: undefined,
          name: '',
          price: undefined,
          teacherName: '',
          age: '',
          url: '',
          startTime: '',
          finishTime: '',
          capacity: undefined,
          surplus: undefined,
          rotationList: []
        }
      }
    }
  },
  methods: {
    // 格式化时间
    parseTime(time, format) {
      return parseTime(time, format)
    },
    // 点击某一门课程，触发查看详情
    handleCourse(course) {
      this.$router.push({ path: '/detail?csId=' + course.id })
    }
  }
}
</script>

<style lang="scss" scoped>
.course {
  cursor: pointer;
  border-radius: 4px;
  margin-bottom: 20px;
  margin-right: 26px;
  //margin: 0 10px 20px 0;
  .course-base {
    padding: 40px 0 0 20px;
    background-color: #FFF;

    .course-name {
      width: 170px;
      padding-top: 14px;
      font-size: 20px;
      font-weight: 700;
      line-height: 28px;
      margin-bottom: 12px;
    }

    .course-techer {
      margin-bottom: 12px;
      display: flex;
      align-items: center;

      .teacher, .age {
        background-color: #f5d220;
        height: 18px;
        padding: 0 6px;
        line-height: 18px;
        border-radius: 9px 9px 0;
        display: inline-block;
        margin-right: 2px;
      }
      .age {
        background-color: #75f520;
        overflow: hidden; /*超出隐藏*/
        text-overflow: ellipsis;/*隐藏后添加省略号*/
        white-space: nowrap;/*强制不换行*/
        width: 70px;
      }
    }

    .course-time {
      font-size: 14px;
      line-height: 14px;
    }

    .course-image {
      width: 170px;
      height: 170px;
    }
  }

  .course-sale {
    height: 70px;
    width: 100%;
    //margin: 20px 0 0;
    padding: 20px 20px;
    font-size: 12px;
    background-color: #FAFAFA;

    .people-info {
      .limit {
        margin-bottom: 9px;
      }
    }

    .price-info {
      text-align: right;
      color: #FF4C4C;
      font-size: 22px;
      font-weight: bold;

      span {
        font-size: 14px;
      }
    }
  }
}
</style>
